home *** CD-ROM | disk | FTP | other *** search
Korn shell script | 1995-03-24 | 3.3 KB | 124 lines |
- #! /bin/ksh
- USAGE='USAGE: install_list [ -d config_prefix ] list_file mount_path map_to_path
- Each line of list_file has an inode number followed by two tabs and
- a file path. Each file path starts with the string passed in
- the mount_path argument. The file or directory is installed
- at the path formed by replacing mount_path with map_to_path.
-
- If a file or directory is listed and its parent directory needs
- to be installed, the parent directory must be in list_file also.
- '
- # (C) Copyright 1995 by Michael Coulter. All rights reserved.
-
- # define functions
-
- # Process parameters
-
- ##echo "install_list: command: $0 $*"
- CONFIG_PREFIX=""
- if [ $# -ge 2 -a "$1" = "-d" ]
- then
- shift # done with -d
- CONFIG_PREFIX="$1"; shift
- fi
- if [ $# -ne 3 ]
- then
- echo "$USAGE" >&2
- echo "$0 Expected 3 arguments, got $#" >&2
- exit 1
- fi
- LIST_FILE="$1"; shift
- if [ ! -r "$LIST_FILE" ]
- then
- echo "$USAGE" >&2
- echo "Unable to read list_file, $LIST_FILE" >&2
- exit 1
- fi
- MOUNT_PATH="$1"; shift
- if [ ! -d "$MOUNT_PATH" ]
- then
- echo "$USAGE" >&2
- echo "No directory at MOUNT_PATH, $MOUNT_PATH" >&2
- exit 1
- fi
- MAP_TO_PATH="$1"; shift
- if [ ! -d "$MAP_TO_PATH" ]
- then
- echo "$USAGE" >&2
- echo "No directory at MAP_TO_PATH, $MAP_TO_PATH" >&2
- exit 1
- fi
-
- # Do it
-
-
- ##echo "install_list: MOUNT_PATH is $MOUNT_PATH MAP_TO_PATH $MAP_TO_PATH"
- cut -f3 "$LIST_FILE" | sort | while read FILE_PATH
- do
- echo "$FILE_PATH"
- if [ "$FILE_PATH" = "${FILE_PATH#$MOUNT_PATH}" ]
- then
- if [ "$FILE_PATH" != '.' ]
- then
- echo "$FILE_PATH is not below $MOUNT_PATH" >&2
- fi
- continue
- fi
- if [ "$FILE_PATH" = "$MOUNT_PATH" ]
- then
- continue # can't install at this level
- fi
- if [ -d "$FILE_PATH" ]
- then
- FILE_DIR="$FILE_PATH"
- else
- FILE_DIR="$(dirname "$FILE_PATH")"
- fi
- if [ "$MAP_TO_PATH" = "/" ]
- then
- DEST_FILE="${FILE_PATH#$MOUNT_PATH}"
- else
- DEST_FILE="${MAP_TO_PATH}/${FILE_PATH#$MOUNT_PATH}"
- fi
-
- ##echo "install_list: DEST_FILE is $DEST_FILE"
- ##echo install_list: install_dir -d "$CONFIG_PREFIX" "$(dirname "$DEST_FILE")" "$MOUNT_PATH" "$MAP_TO_PATH"
- install_dir -d "$CONFIG_PREFIX" "$(dirname "$DEST_FILE")" "$MOUNT_PATH" "$MAP_TO_PATH"
- if [ -f "$FILE_PATH" ]
- then
- if [ -L "$DEST_FILE" ]
- then
- rm "$DEST_FILE"
- fi
- if [ -f "$DEST_FILE" ]
- then
- echo "$DEST_FILE is already a file"
- else
- cp "${FILE_PATH}" "$DEST_FILE"
-
- # Kludge, map in a .el when .elc is mapped in.
- ##echo "install_list: FILE_PATH is '$FILE_PATH'"
- if [ "$FILE_PATH" != "${FILE_PATH%.elc}" ]
- then
- EL_FILE="${FILE_PATH%.elc}.el"
- ##echo "install_list: EL_FILE is '$EL_FILE'"
- if [ -f "$EL_FILE" -a -L "${DEST_FILE%.elc}.el" ]
- then
- rm "${DEST_FILE%.elc}.el"
- cp "$EL_FILE" "${DEST_FILE%.elc}.el"
- fi
- fi
- fi
- else
- if [ ! -d "$FILE_PATH" ]
- then
- echo "$FILE_PATH is not a file or directory!" >&2
- continue
- fi
- if [ -L "$DEST_FILE" ]
- then
- install_dir -d "$CONFIG_PREFIX" "$DEST_FILE" "$MOUNT_PATH" "$MAP_TO_PATH"
- fi
- fi
- done
-